package com.example.mgs;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;


@Slf4j
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication(scanBasePackages = {"com.example.mgs", "com.example.common"})
@ComponentScan(basePackages = {"com.example.mgs", "com.example.common"})
public class MessagesApplication {

    public static void main(String[] args) {
        SpringApplication.run(MessagesApplication.class, args);
//        ConfigurableApplicationContext context = SpringApplication.run(MessagesApplication.class, args);
//        // 检查Nacos配置
//        NacosDiscoveryProperties nacosProperties = context.getBean(NacosDiscoveryProperties.class);
//        log.info("Nacos配置信息：");
//        log.info("服务名称: {}", nacosProperties.getService());
//        log.info("命名空间: {}", nacosProperties.getNamespace());
//        log.info("分组: {}", nacosProperties.getGroup());
//        log.info("注册地址: {}", nacosProperties.getServerAddr());
//        log.info("是否注册: {}", nacosProperties.isRegisterEnabled());
//
//        // 检查服务注册状态
//        try {
//            NamingService namingService = nacosProperties.namingServiceInstance();
//            String serviceName = nacosProperties.getService();
//            List<Instance> instances = namingService.getAllInstances(serviceName);
//            log.info("服务实例数量: {}", instances.size());
//            for (Instance instance : instances) {
//                log.info("实例信息: {}", instance);
//            }
//        } catch (Exception e) {
//            log.error("检查服务注册状态失败", e);
//        }
    }

}
